interface PickerObj {
    code: string;
    text: string;
    children: Array<PickerObj>;
}

export default {
    
    // 根据code获取中文
    getValue(code: Array<String>, data: Array<PickerObj>): String {
        let ret1: PickerObj | undefined,
            ret2: PickerObj | undefined,
            ret3: PickerObj | undefined;

        if (code.length == 0) {
            return "";
        }

        ret1 = data.find(item => {
            return item.code === code[0];
        });
        if (!ret1) {
            return "";
        }

        if (code.length > 1) {
            ret2 = ret1.children.find(item => {
                return item.code === code[1];
            });
            if (!ret2) {
                return ret1.text;
            }
        } else {
            return ret1.text;
        }

        if (code.length > 2) {
            ret3 = ret2.children.find(item => {
                return item.code === code[2];
            });
            if (!ret3) {
                return `${ret1.text}-${ret2.text}`;
            }
        } else {
            return `${ret1.text}-${ret2.text}`;
        }

        return `${ret1.text}-${ret2.text}-${ret3.text}`;
    }
};
